<?php

require 'lib/Yahoo.inc.php';

if(!isset($_REQUEST['oauth_verifier'])){
	YahooSession::clearSession();
}

$session = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);
	
if(is_object($session))
{
	$user = $session->getSessionedUser();
	$profile = http_build_query($user->getProfile());
		
	if(isset($_SESSION['callback']))
	{
		$sUrlCallback = $_SESSION['callback'];
		$security_token = $_SESSION['security_token'];
		unset($_SESSION['callback']);
		$sForm =  <<<EOF
<form action="$sUrlCallback" method="POST" id="yahoo_connect">
	<input name="contact" type="hidden" value="$profile"/>
	<input name="service" type="hidden" value="4"/>
	<input type="hidden" value="$security_token" name="core[security_token]">
	<input name="get_success" type="hidden" value="1"/>
</form>
<script language="JavaScript" type="text/javascript">
	window.onload = submitYahoo;
	function submitYahoo()
	{
		document.getElementById('yahoo_connect').submit();
	}
</script>
EOF;
		echo $sForm;
	}
}



